<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=8" />	
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>兴凯湖三维地形</title>
		
        <!--<script type="text/javascript" src="Map2D/libs/SuperMap.Include.js" ></script>
          <script type="text/javascript" src="Map3D/script/stationBubble.js" ></script>
          <script type="text/javascript" src="Map3D/script/model.js" ></script>
        -->
        <script type="text/javascript" src="Map3D/script/Include3D.js" ></script>
        <script type="text/javascript" src="Map3D/script/updateStyles.js" ></script>
        <script type="text/javascript" src="Map3D/script/station.js" ></script>
        <script type="text/javascript" src="Map3D/script/waterplant.js" ></script>
        <script type="text/javascript" src="Map3D/script/jquery-1.9.1.min.js" ></script>
        <script type="text/javascript" src="Map3D/script/Math.uuid.js" ></script>
		<script type="text/javascript">
			var sceneControl = null;
			var scene = null;
			var asyncHelper =null;
			var trackingLayer = null;
			///管理三维要素原始数据
            var  managerFeature =[];

			var htmlUrl ="";
			var mapUrl = "172.16.157.44:8090";
			var baseStationUrlPrefix = htmlUrl+"/Waterworks/pipeline/textureAction/stationTexture/";
			var baseWaterplantUrlPrefix = htmlUrl+"/Waterworks/pipeline/textureAction/waterplantTexture/";
			//判断网页的打开方式是本地打开还是通过网络打开
			if(htmlUrl == "")
			{
				htmlUrl = "http://localhost:8090";
			}
			else
			{
			    //获取当前网址，如： http://localhost:8080/Tmall/index.jsp
                var curWwwPath=window.document.location.href;
                //获取主机地址之后的目录如：/Tmall/index.jsp
                var pathName=window.document.location.pathname;
                var pos=curWwwPath.indexOf(pathName);
                //获取主机地址，如： http://localhost:8080
                htmlUrl=curWwwPath.substring(0,pos);
			}
			//不同的打开方式url赋值不同
			if(mapUrl == "")
			{
				mapUrl = "http://localhost:8090";
			}
			else
			{
				mapUrl = "http://" + mapUrl;
			}
			var sceneUrl = mapUrl + "/iserver/services/3D-HB/rest/realspace";
			var pictureurl = mapUrl + "/RealspaceSample/iClient.png";
			//alert(sceneUrl);
			function onPageLoad() 
			{
				//初始化三维场景控件
				try
				{
					//初始化三维场景控件实例,参数为包含控件的HTML元素
					sceneControl = new SuperMap.Web.UI.Controls.SceneControl($get("sceneControlDiv"), initCallback, failedCallback);
				}
				catch(e)
				{   
					//若没有安装插件，则抛出该异常
					if (e.name == SuperMap.Web.Realspace.ExceptionName.PlugInNotInstalled) 
					{
						var url = mapUrl + "/iserver/iClient/for3D/Setup.exe";
						document.write(" <a href='"+url+"'>未检测到 SuperMap iClient 7C for 3D 插件，请单击此处下载并安装插件。 </a>");
						return;
					}
					//若使用非IE浏览器，则抛出该异常
					else if (e.name == SuperMap.Web.Realspace.ExceptionName.BrowserNotSupport) 
					{
						document.write(" <p>SuperMap iClient 7C for 3D 目前仅支持 InternetExplorer 浏览器，请更换浏览器后重新尝试加载本页面。 </p>");
						return;
					}
					//抛出其他异常
					else
					{
						alert(e.message);
					}    
				}               
			}


			//控件初始化完成后的回调函数，初始化完成之后才能进行数据加载             
			function initCallback() 
			{
				//获取Realspace控件的场景，控件和场景是一对一的捆绑关系
				scene = sceneControl.get_scene();
				trackingLayer = scene.get_trackingLayer3D();

			    //指定图层名称
				var sceneAddress = sceneUrl;
				var sceneName ="zhijiangshi1@HB";

				//从指定的服务器获取场景的图层服务信息，获取成功返回 True
				var bLoad = scene.open(sceneUrl, sceneName);

				if (bLoad) 
			     { 

			     	var camera = new SuperMap.Web.Realspace.Camera(111.75, 30.38, 40000);
				    camera.set_tilt(45.978013297770225);
				    scene.get_flyingOperator().flyTo(camera,5000,SuperMap.Web.Realspace.FlyingMode.CAMERA_NORMAL);
				    setTimeout(initData,5000);

			    }
			    else
			    {
			    	alert("场景加载失败！");
			    }
			}


			function initData()
			{
				var stationHelper = new StationHelper();
			    stationHelper.getStations();

			    var waterplantHelper = new WaterplanHelper();
			    waterplantHelper.getWaterplants();

			    setInterval(updateNearestFeatureStyles,5000);
			}

            /**************************** 执行 SQL 查询 start ****************************/
            function DoSqlQuery() {
                scene.get_trackingLayer3D().removeAll();

                queryDatasetName = document.getElementById("layerList").options[document.getElementById("layerList").selectedIndex].text;
                var attributeFilter = document.getElementById("filterParameterString").value;


                var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;

                getFeatureParam = new SuperMap.REST.FilterParameter({
                    name: queryDatasetName + "@3DDataset",
                    attributeFilter: attributeFilter
                });
                getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
                    queryParameter: getFeatureParam,
                    datasetNames: ["3DDataset:" + queryDatasetName]
                });
                getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(queryServiceUrl, {
                    eventListeners: {"processCompleted": onQueryComplete, "processFailed": processFailed}});

                getFeatureBySQLService.processAsync(getFeatureBySQLParams);

            }

						//加载图片对象完成后的回调函数
						//                            
			function  createTextFeature()
			{
				var p1 = createTextPart("11111",0.2);                                            
			    var p2 = createTextPart("22222",0.3);
				var p3 = createTextPart("33333",0.4);
				var p4 = createTextPart("44444",0.5);
				var textArray = [p1,p2,p3,p4];
				//var textArray = [p1];
				var text3D = new SuperMap.Web.Core.GeoText3D(textArray);
				var feature3D = new SuperMap.Web.Core.Feature3D();
				var textStyle = new SuperMap.Web.Core.TextStyle3D();
				textStyle.set_foreColor(new SuperMap.Web.Core.Color(255,0,0,255));
				textStyle.set_backColor(new SuperMap.Web.Core.Color(0,255,0,255));
				textStyle.set_outline(true);
				textStyle.set_fontName("微软雅黑");
				feature3D.set_textStyle3D(textStyle);
				var style = new SuperMap.Web.Core.Style3D();
				style.set_fillForeColor(new SuperMap.Web.Core.Color(0,0,255,255));
				style.set_markerColor(new SuperMap.Web.Core.Color(0,0,255,255));
				style.set_fill3DMode(SuperMap.Web.Core.Fill3DMode.FACE);
				feature3D.set_style3D(style);
				feature3D.set_geometry(text3D);
				return feature3D;

			}
			function createTextPart(str,height)
			{

				var anchorPoint1 = new SuperMap.Web.Core.Point3D(0.5,height,0);
				var txtPart3D1 = new SuperMap.Web.Core.TextPart3D(str, anchorPoint1);
				return txtPart3D1;
			}
			function createTextFeature3D(height,space,str)
			{

				var anchorPoint1 = new SuperMap.Web.Core.Point3D(111.7549171858,30.4229139493+space,height);
				var txtPart3D1 = new SuperMap.Web.Core.TextPart3D(str, anchorPoint1);
				var textArray1 = [txtPart3D1];
				var text3D1 = new SuperMap.Web.Core.GeoText3D(textArray1);
						
				var feature3D1 = new SuperMap.Web.Core.Feature3D();
				feature3D1.set_geometry(text3D1);
				var textStyle = new SuperMap.Web.Core.TextStyle3D();
				textStyle.set_foreColor(new SuperMap.Web.Core.Color(255,0,0,255));
				textStyle.set_backColor(new SuperMap.Web.Core.Color(0,0,0,255));
				textStyle.set_outline(true);
				textStyle.set_fontName("微软雅黑");
				textStyle.set_fontHeight(5);
				textStyle.set_fontWidth(50);
				textStyle.set_isSizeFixed(false);
				//textStyle.set_fixedSize(100);
				feature3D1.set_textStyle3D(textStyle);
				return  feature3D1;
			}
			function fetchPicture3DFinished(geoPicture3D) 
			{
				//设置图片的大小和位置，屏幕图层有两种单位：像素和比例。这里以像素为单位
				geoPicture3D.set_height(0.05);
				geoPicture3D.set_width(0.05);
				geoPicture3D.set_position(new SuperMap.Web.Core.Point3D(0.05, 0.05, 0));
				//屏幕图层中只能加feature3D，所以这里得把geometry构造成feature3D对象
				var feature3d = new SuperMap.Web.Core.Feature3D();
				feature3d.set_geometry(geoPicture3D);
			
				var screenLayer = scene.get_screenLayer3D();
				//设置屏幕图层的单位为像素
				// screenLayer.set_xUnit(SuperMap.Web.Realspace.ScreenCoordinateUnit.PIXEL);
				// screenLayer.set_yUnit(SuperMap.Web.Realspace.ScreenCoordinateUnit.PIXEL);
				//设置屏幕图层可见
				screenLayer.set_isVisible(true);
				//将feature3D加入屏幕图层
				screenLayer.add(feature3d, "SuperMap");
				scene.get_flyingOperator().flyTo(new SuperMap.Web.Realspace.Camera(100, 100, 0));
			}
			function  initButton()
			{

			}
			function createButton()
			{

				    //scene.get_screenLayer3D().set_isVisible(true);
			}
            function SceneLoad()
            {
            	//alert("loading...")
            					//指定场景的服务器地址
				var sceneAddress = sceneUrl;

				//指定图层名称
				var sceneName ="zhijiangshi1@HB";
			   
			    console.log(sceneAddress);
			    //alert("before open");

				if(scene.open(sceneAddress, sceneName));
				{

					var layer3DStation = scene.get_layer3Ds().get_item("监测点@HB"); 
				}
				// {

				// 	//飞行到场景的第1个图层的地理范围
				// 	var layer3D = scene.get_layer3Ds().get_item(0);
    //                 if(layer3D!=null)
    //                 {
    //                 	var geobound = layer3D.get_bounds(); 
    //                 	scene.get_flyingOperator().flyToBounds(geobound);	  
    //                 }			
				// 	//给场景重命名
				// 	scene.set_name("hello");
				// }
				// else
				// {
				// 	alert("三维场景加载失败！");
				// }
 
				//获取场景中的图层
				//alert("get layer3D...")
			    

/*				var layer3D = scene.get_layer3Ds().get_item("监测点@HB"); 

				if (layer3D != null)
				{
					//获取图层的地理范围，并飞行到该范围
					var geobound = layer3D.get_bounds();  
					console.log(geobound);
					scene.get_flyingOperator().flyToBounds(geobound);
				}
				else
				{
					alert("layer3D==null")
				}*/
            }
            function initFeature3D()
            {
            	// var tp1 = new SuperMap.Web.Core.GeoText3D("text1",new SuperMap.Web.Core.Point3D(117.7578,30.4247,1));
            	// var tp2 = new SuperMap.Web.Core.GeoText3D("text2",new SuperMap.Web.Core.Point3D(117.7578,30.4247,2));
            	// var tp3 = new SuperMap.Web.Core.GeoText3D("text3",new SuperMap.Web.Core.Point3D(117.7578,30.4247,3));
            	// var tp4 = new SuperMap.Web.Core.GeoText3D("text4",new SuperMap.Web.Core.Point3D(117.7578,30.4247,4));
            	// var t1 = new SuperMap.Web.Core.GeoText3D([tp1,tp2,tp3,tp4]);
            	// var f1 = new SuperMap.Web.Core.Feature3D();
             //    f1.geometry=t1;
            	// var infoFeature = new SuperMap.Web.Core.Feature3Ds();
            	// infoFeature.insert(0,f1);
            	// scene.get

             
            var trackingLayer3D = scene.get_trackingLayer3D();

			var feature3D = new SuperMap.Web.Core.Feature3D();
            var geoText3D = new SuperMap.Web.Core.GeoText3D();
            var textPart3D = new SuperMap.Web.Core.TextPart3D('总距离：' + 3 + '米', new SuperMap.Web.Core.Point3D(117.7578,30.4247,1));
            var textStyle3D = new SuperMap.Web.Core.TextStyle3D();
            geoText3D.addPart(textPart3D);
            textStyle3D.set_fontScale(0.8);
            textStyle3D.set_opaqueRate(100);
            textStyle3D.set_foreColor(new SuperMap.Web.Core.Color(255, 255, 255, 255));
            textStyle3D.set_bold(true);
            feature3D.set_geometry(geoText3D);
            feature3D.set_textStyle3D(textStyle3D);
            trackingLayer3D.refresh();
            var index = trackingLayer3D.add(feature3D, 'posx');

            }
			//控件初始化失败后的回调函数
			function failedCallback() 
			{
				alert("Realspace initialized failed!");
			}        
		</script>
	</head>

	<body onLoad="onPageLoad()" >
		  <div id="sceneControlDiv" style="position:absolute;z-index:-1;left:5px;top:5px;right:5px;bottom:5px;background-color:#00ff00" ></div>
	</body>
</html>
